import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

var userInfo = JSON.parse(localStorage.getItem("userInfo"));


const constantRoutes = [{
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    children: [{
      path: '/',
      name: 'home',
      component: () => import('@/views/home/home'),
      meta: {
        title: '数据展示',
        icon: 'fenxi'
      }
    }, ]
  },
  {
    path: '/',
    component: Layout,
    meta: {
      title: '货物管理',
      icon: 'huowu'
    },
    children: [{
        path: '/order',
        name: 'order',
        component: () => import('@/views/cargo/order'),
        meta: {
          title: '发出包裹查询',
          icon: "order"
        }
      },

      {
        path: '/zhuanyun',
        name: 'zhuanyun',
        component: () => import('@/views/cargo/zhuanyun'),
        meta: {
          title: '转运订单管理',
          icon: "zhuanyun"
        }
      },
      {
        path: '/baoguo',
        name: 'baoguo',
        component: () => import('@/views/cargo/baoguo'),
        meta: {
          title: '包裹管理',
          icon: "gl"
        }
      },
      {
        path: '/hdfk',
        name: 'hdfk',
        component: () => import('@/views/cargo/hdfk'),
        meta: {
          title: '货到付款',
          icon: "hdfk"
        }
      },
      {
        path: '/huoguigl',
        name: 'huoguigl',
        component: () => import('@/views/cargo/huoguigl'),
        meta: {
          title: '货柜管理',
          icon: "gl"
        }
      },
      {
        path: '/hongcaitj',
        name: 'hongcaitj',
        component: () => import('@/views/cargo/hongcaitj'),
        meta: {
          title: '耗材统计',
          icon: "gl"
        }
      },
      {
        path: '/qingdian',
        name: 'qingdian',
        component: () => import('@/views/cargo/qingdian'),
        meta: {
          title: '包裹清点',
          icon: "qingdian"
        }
      },
      {
        path: '/tuihuo',
        name: 'tuihuo',
        component: () => import('@/views/cargo/tuihuo'),
        meta: {
          title: '包裹退货',
          icon: "tuihuo"
        }
      },
      {
        path: '/fuwu',
        name: 'fuwu',
        component: () => import('@/views/cargo/fuwu'),
        meta: {
          title: '服务请求',
          icon: "fuwu"
        }
      },
      {
        path: '/diaocha',
        name: 'diaocha',
        component: () => import('@/views/cargo/diaocha'),
        meta: {
          title: '理赔调查',
          icon: "diaocha"
        }
      },
      {
        path: '/fenxiang',
        name: 'fenxiang',
        component: () => import('@/views/cargo/fenxiang'),
        meta: {
          title: '包裹分箱',
          icon: "fenxiang"
        }
      }
    ]
  },

  {
    path: '/',
    component: Layout,
    meta: {
      title: '会员管理',
      icon: 'members'

    },
    children: [{
        path: '/info',
        name: 'info',
        component: () => import('@/views/members/info'),
        meta: {
          title: '会员信息管理',
          icon: 'info'
        }
      }, {
        path: '/grade',
        name: 'grade',
        component: () => import('@/views/members/grade'),
        meta: {
          title: '会员等级制度',
          icon: 'grade'
        }
      }, {
        path: '/grouping',
        name: 'grouping',
        component: () => import('@/views/members/grouping'),
        meta: {
          title: '会员分组管理',
          icon: 'grouping'
        }
      },
      {
        path: '/fenzu',
        name: 'fenzu',
        component: () => import('@/views/members/fenzu'),
        meta: {
          title: '查询分组用户',
          icon: 'fenzu'
        }
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    meta: {
      title: '网站管理',
      icon: 'setting',
      hidden: true
    },
    children: [{
      path: '/adminAccount',
      name: 'adminAccount',
      component: () => import('@/views/adminAccount/index'),
      meta: {
        title: '管理员帐号管理',
        icon: 'adminaccount',
        hidden: true
      }
    }, {
      path: '/setting',
      name: 'setting',
      component: () => import('@/views/setting/index'),
      meta: {
        title: '轮播图管理',
        icon: "gl",
        hidden: true
      }
    }, {
      path: '/notice',
      name: 'notice',
      component: () => import('@/views/setting/notice'),
      meta: {
        title: '公告管理',
        icon: "gl",
        hidden: true
      }
    },{
      path: '/service',
      name: 'service',
      component: () => import('@/views/setting/service'),
      meta: {
        title: '代购服务管理',
        icon: "service",
        hidden: true
      }
    },
    {
      path: '/items',
      name: 'items',
      component: () => import('@/views/setting/items'),
      meta: {
        title: '服务项目管理',
        icon: "items",
        hidden: true
      }
    },
    ]
  },
  // {
  //   path: '/',
  //   component: Layout,
  //   meta: {
  //     title: '权限管理',
  //     icon: 'adminaccount'
  //   },
  //   children: [

  //   ]
  // },
  // 404 page must be placed at the end !!!
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
